home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13371 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q: throwing exceptions in constructors
  5. Date: 25 Mar 1996 11:52:00 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4j61d0$but@news1.h1.usa.pipeline.com>
  8. References: <opu3ze7xf4.fsf@sweetbay.will.uiuc.edu>
  9. NNTP-Posting-Host: 38.8.120.13
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Mar 24, 1996 19:51:11 in article <Q: throwing exceptions in
  16. constructors>, 'Dragos-Anton Manolescu <manolesc@uiuc.edu>' wrote: 
  17.  
  18.  
  19. >I was wondering if it's possible to throw an exception from within a 
  20. >constructor (a word of caution: this is my first attempt to use 
  21. >exceptions :-) Suppose the constructor calls new and this fails. Then 
  22. >I would like to throw an exception to inform the calling program that 
  23. >an abnormal situation occured. Is this possible? I tried something 
  24. >like: 
  25. >... 
  26. >MyClass myObject(1,2,3) 
  27. >... 
  28. >inside a try statement but the compiler complained (I use g++ 2.7.2, 
  29. >BTW). Am I doing something wrong? What would be an elegant way to 
  30. >handle this? 
  31. Yes, it's possible.  Post a sample of your code and the wording 
  32. the compiler's error message, so we can point out how you may 
  33. correct your problem. 
  34.  
  35. BTW, Scott Meyers in his book "More Effective C++" devotes an  
  36. entire chapter to dealing with exceptions within constructors 
  37. and destructors.  IMO, this book is required reading as soon  
  38. as one has progressed beyond the newby status.  The surprising 
  39. part about this book is that is contains some eye openers for 
  40. the experts as well as those in the intermediate/beginner 
  41. categories.   
  42.  
  43. This book was written in November 95 and is about as current 
  44. as you can get.  Mr. Meyers talks about most of the recent 
  45. additions/changes to the language as well as pointing out 
  46. the proposed changes which could affect the way you code 
  47. today in preparation for tomorrow. 
  48.  
  49. Pardon the sales pitch.  I'm not connected with Scott Meyers 
  50. in any way, I just think that it's an excellent book. 
  51.   
  52. -- 
  53. Pete Grant 
  54. Kalevi, Inc. 
  55. Software Engineering & development
  56.